package ru.lukyanets.transmission.client.ui.controller;

import com.google.inject.Inject;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;
import ru.lukyanets.transmission.client.action.AddTorrentFileAction;
import ru.lukyanets.transmission.client.action.AddTorrentUrlAction;
import ru.lukyanets.transmission.client.action.ExitAction;
import ru.lukyanets.transmission.protocol.client.Priority;

import java.net.URL;
import java.util.ResourceBundle;

/**
 * @author slukyanets
 * @noinspection unused
 */
public class MainMenuController implements Initializable {
    @FXML
    private Menu menuPriority;
    @FXML
    private MenuItem open;
    @FXML
    private MenuItem exit;
    @FXML
    public MenuItem openUrl;

    @Inject
    private AddTorrentFileAction addTorrentFileAction;
    @Inject
    private AddTorrentUrlAction addTorrentUrlAction;
    @Inject
    private ExitAction exitAction;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        for (Priority priority : Priority.values()) {
            MenuItem menuItem = new MenuItem(resources.getString("torrent.priority." + priority));
            menuItem.getStyleClass().add(priority.toString());
            menuItem.setOnAction(event -> changePriority(priority));
            menuPriority.getItems().add(menuItem);
        }
        addTorrentFileAction.configure(open);
        addTorrentUrlAction.configure(openUrl);
        exitAction.configure(exit);
    }

    private void changePriority(Priority priority) {
        System.out.println("Priority changed to " + priority);
    }
}
